package com.milling.web.controller.business;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import com.milling.business.domain.WmsTxnInfo;
import com.milling.business.service.IWmsTxnInfoService;
import com.milling.common.annotation.Log;
import com.milling.common.core.controller.BaseController;
import com.milling.common.core.domain.AjaxResult;
import com.milling.common.core.page.TableDataInfo;
import com.milling.common.enums.BusinessType;
import com.milling.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 交易信息Controller
 *
 * @author X
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/business/txninfo")
public class WmsTxnInfoController extends BaseController
{
    @Autowired
    private IWmsTxnInfoService wmsTxnInfoService;

    /**
     * 查询交易信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:txninfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsTxnInfo wmsTxnInfo)
    {
        startPage();
        List<WmsTxnInfo> list = wmsTxnInfoService.selectWmsTxnInfoList(wmsTxnInfo);
        return getDataTable(list);
    }

    /**
     * 导出交易信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:txninfo:export')")
    @Log(title = "交易信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsTxnInfo wmsTxnInfo)
    {
        List<WmsTxnInfo> list = wmsTxnInfoService.selectWmsTxnInfoList(wmsTxnInfo);
        ExcelUtil<WmsTxnInfo> util = new ExcelUtil<WmsTxnInfo>(WmsTxnInfo.class);
        util.exportExcel(response, list, "交易信息数据");
    }

    /**
     * 获取交易信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:txninfo:query')")
    @GetMapping(value = "/{txnId}")
    public AjaxResult getInfo(@PathVariable("txnId") String txnId)
    {
        return success(wmsTxnInfoService.selectWmsTxnInfoByTxnId(txnId));
    }

    /**
     * 新增交易信息
     */
    @PreAuthorize("@ss.hasPermi('business:txninfo:add')")
    @Log(title = "交易信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsTxnInfo wmsTxnInfo)
    {
        return toAjax(wmsTxnInfoService.insertWmsTxnInfo(wmsTxnInfo));
    }

    /**
     * 修改交易信息
     */
    @PreAuthorize("@ss.hasPermi('business:txninfo:edit')")
    @Log(title = "交易信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsTxnInfo wmsTxnInfo)
    {
        return toAjax(wmsTxnInfoService.updateWmsTxnInfo(wmsTxnInfo));
    }

    /**
     * 删除交易信息
     */
    @PreAuthorize("@ss.hasPermi('business:txninfo:remove')")
    @Log(title = "交易信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{txnIds}")
    public AjaxResult remove(@PathVariable String[] txnIds)
    {
        return toAjax(wmsTxnInfoService.deleteWmsTxnInfoByTxnIds(txnIds));
    }
}
